package com.douban.business.vo;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.douban.constants.DoubanConstant;

public class ItemVO implements Comparable<ItemVO>{

	String id;
	String title;
	String intro;
	Date date;
	
	public ItemVO(String id, String title, String intro, String date){
		this.id = id;
		this.title = title;
		this.intro = intro;
		setDate(date);
	}

	public ItemVO(String id, String title, String intro, Date date){
		this.id = id;
		this.title = title;
		this.intro = intro;
		this.date = date;
	}
	
	public ItemVO() {
		this.id = null;
		this.title = null;
		this.intro = null;
		this.date = null;
		
	}
	
	public boolean compare(){
		return false;		
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(String date) {
		DateFormat df = new SimpleDateFormat(DoubanConstant.DATE_FORMAT.getValue());
		try {
			this.date = df.parse(date);
		} catch (ParseException e) {
			//we don't care if the date is valid or not
			this.date = null;
		}
	}

	public boolean isReady() {
		// TODO Auto-generated method stub
		return this.id!=null&&this.title!=null
				&&this.intro!=null&&this.date!=null;
	}

	@Override
	public int compareTo(ItemVO o) {
		// TODO Auto-generated method stub
		if(o==null){
			return -1;
		}
		if(this.date!=null){
			return this.date.compareTo(o.getDate()) ;
		}
		
		return 0;
	}
}
